<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\admin\model\Block;
use app\admin\model\News as NewsModel;
use Think\Db;

/**
 * 首页接口
 */
class News extends Api
{
    protected $noNeedLogin = [];
    protected $noNeedRight = ['*'];

    /**
     * 新闻列表
     * @return void
     */
    public function index()
    {
        $cate_id = $this->request->get('cate_id', 0);
        $list = (new NewsModel())->getList(['status' => 1, 'cate_id' => $cate_id], 10,'id,name,image,createtime', 'weigh desc');
        foreach ($list['data'] as &$val){
            $val['createtime'] =date('Y-m-d',$val['createtime']);
        }
        $this->success('请求成功', ['news'=>$list]);
    }

    /**
     * 新闻详情
     * @return void
     */
    public function detail()
    {
        $id = $this->request->get('id');
        $info = (new NewsModel())->getInfoById($id,'id,name,image,createtime,updatetime,content');
//        dump($info);die;
        isset($info['createtime'])&&$info['createtime'] = \fast\Date::human($info['createtime']);
        $info['content'] = htmlspecialchars_decode( $info['content']);
        $this->success('请求成功', $info);
    }

}
